home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / ai.trm < prev    next >
Text File  |  1993-09-15  |  7KB  |  347 lines

  1. /*
  2.  * $Id: ai.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - ai.trm */
  7. /*
  8.  * Copyright (C) 1991, 1992   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *     aifm
  26.  *
  27.  * AUTHORS
  28.  *  Ray Ghanbari
  29.  * 
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  *
  32.  * The 'aifm' driver produces files editable by Adobe Illustrator 3.0
  33.  * To change font to Courier and font size to 20pts use 
  34.  * 'set term aifm "Courier" 20'.
  35.  * To switch to color output use
  36.  * 'set term aifm color'.
  37.  */
  38.  
  39.  
  40. /* AIFM driver by Ray Ghanbari, ray@mtl.mit.edu, 
  41.  *    based on PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
  42.  
  43. char ai_font[MAX_ID_LEN+1] = "Times-Roman" ; /* name of font */
  44. int ai_fontsize = 14;                     /* size of font in pts */
  45. TBOOLEAN ai_color = FALSE;
  46. TBOOLEAN ai_stroke = FALSE;
  47. int ai_page=0;            /* page count */
  48. int ai_path_count=0;     /* count of lines in path */
  49. int ai_ang=0;            /* text angle */
  50. enum JUSTIFY ai_justify=LEFT;    /* text is flush left */
  51.  
  52.  
  53. #define AI_XOFF    50    /* page offset in pts */
  54. #define AI_YOFF    50
  55.  
  56. #define AI_XMAX 5000
  57. #define AI_YMAX 3500
  58.  
  59. #define AI_XLAST (AI_XMAX - 1)
  60. #define AI_YLAST (AI_YMAX - 1)
  61.  
  62. #define AI_VTIC (AI_YMAX/80)
  63. #define AI_HTIC (AI_YMAX/80)
  64.  
  65. #define AI_SC (10.0)                /* scale is 1pt = 10 units */
  66. #define AI_LW (0.5*AI_SC)        /* linewidth = 0.5 pts */
  67.  
  68. #define AI_VCHAR (14*AI_SC)        /* default is 14 point characters */
  69. #define AI_HCHAR (14*AI_SC*6/10)
  70.  
  71.  
  72. AI_options()
  73. {
  74.     extern struct value *const_express();
  75.     extern double real();
  76.  
  77.     if (!END_OF_COMMAND) {
  78.         if (almost_equals(c_token,"d$efault")) {
  79.             ai_color=FALSE;
  80.             strcpy(ai_font,"Times-Roman");
  81.             ai_fontsize = 14;
  82.             c_token++;
  83.         }
  84.     }
  85.  
  86.     if (!END_OF_COMMAND) {
  87.         if (almost_equals(c_token,"m$onochrome")) {
  88.             ai_color=FALSE;
  89.             c_token++;
  90.         }
  91.         else if (almost_equals(c_token,"c$olor")) {
  92.             ai_color=TRUE;
  93.             c_token++;
  94.         }
  95.     }
  96.  
  97.     if (!END_OF_COMMAND && isstring(c_token)) {
  98.         quote_str(ai_font,c_token);
  99.         c_token++;
  100.     }
  101.  
  102.     if (!END_OF_COMMAND) {
  103.         /* We have font size specified */
  104.         struct value a;
  105.         ai_fontsize = (int)real(const_express(&a));
  106.         c_token++;
  107.         term_tbl[term].v_char = (unsigned int)(ai_fontsize*AI_SC);
  108.         term_tbl[term].h_char = (unsigned int)(ai_fontsize*AI_SC*6/10);
  109.     }
  110.  
  111.     sprintf(term_options,"%s \"%s\" %d",
  112.         ai_color ? "color" : "monochrome",ai_font,ai_fontsize);
  113. }
  114.  
  115.  
  116. AI_init()
  117. {
  118.     ai_page = 0;
  119.     fprintf(outfile,"%%!PS-Adobe-2.0 EPSF-1.2\n");
  120.     fprintf(outfile,"%%%%BoundingBox: %d %d %d %d\n", AI_XOFF,AI_YOFF,
  121.         (int)((AI_XMAX)/AI_SC+0.5+AI_XOFF), 
  122.         (int)((AI_YMAX)/AI_SC+0.5+AI_YOFF) );
  123.     fprintf(outfile,"%%%%Template:\n");
  124.     fprintf(outfile,"%%%%EndComments\n");
  125.     fprintf(outfile,"%%%%EndProlog\n");
  126. }
  127.  
  128.  
  129. AI_graphics()
  130. {
  131.     ai_page++;
  132. /*    fprintf(outfile,"%%%%Page: %d %d\n",ai_page,ai_page);*/
  133.     fprintf(outfile,"0 G\n");
  134.     fprintf(outfile,"1 j\n");
  135.     fprintf(outfile,"1 J\n");
  136.     fprintf(outfile,"u\n");
  137.     ai_path_count = 0;
  138.     ai_stroke = FALSE;
  139. }
  140.  
  141.  
  142. AI_text()
  143. {
  144.     if (ai_stroke) {
  145.         fprintf(outfile,"S\n");
  146.         ai_stroke = FALSE;
  147.     }
  148.     fprintf(outfile,"U\n");
  149.     ai_path_count = 0;
  150. }
  151.  
  152.  
  153. AI_reset()
  154. {
  155.     fprintf(outfile,"%%%%Trailer\n");
  156. /*    fprintf(outfile,"%%%%Pages: %d\n",ai_page);*/
  157. }
  158.  
  159.  
  160. AI_linetype(linetype)
  161. int linetype;
  162. {
  163.     if (ai_stroke) {
  164.         fprintf(outfile,"S\n");
  165.         ai_stroke = FALSE;
  166.     }
  167.     switch(linetype) {
  168.         case -2 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC*2.0);
  169.                 if (ai_color) {
  170.                     fprintf(outfile,"0 0 0 1 K\n");
  171.                 }
  172.                 else {                
  173.                     fprintf(outfile,"[] 0 d\n");
  174.                 }
  175.                 break;
  176.                 
  177.         case -1 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC/2.0);
  178.                 if (ai_color) {
  179.                     fprintf(outfile,"0 0 0 1 K\n");
  180.                 }
  181.                 else {                
  182.                     fprintf(outfile,"[1 2] 0 d\n");
  183.                 }
  184.                 break;
  185.                 
  186.         case 0 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  187.                 if (ai_color) {
  188.                     fprintf(outfile,"1 0 1 0 K\n");
  189.                 }
  190.                 else {                
  191.                     fprintf(outfile,"[] 0 d\n");
  192.                 }
  193.                 break;
  194.                 
  195.         case 1 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  196.                 if (ai_color) {
  197.                     fprintf(outfile,"1 1 0 0 K\n");
  198.                 }
  199.                 else {                
  200.                     fprintf(outfile,"[4 2] 0 d\n");
  201.                 }
  202.                 break;
  203.                 
  204.         case 2 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  205.                 if (ai_color) {
  206.                     fprintf(outfile,"0 1 1 0 K\n");
  207.                 }
  208.                 else {                
  209.                     fprintf(outfile,"[2 3] 0 d\n");
  210.                 }
  211.                 break;
  212.                 
  213.         case 3 :  fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  214.                 if (ai_color) {
  215.                     fprintf(outfile,"0 1 0 0 K\n");
  216.                 }
  217.                 else {                
  218.                     fprintf(outfile,"[1 1.5] 0 d\n");
  219.                 }
  220.                 break;
  221.                 
  222.         case 4 :  fprintf(outfile,"%f w\n",AI_LW/AI_SC);
  223.                 if (ai_color) {
  224.                     fprintf(outfile,"1 0 0 0 K\n");
  225.                 }
  226.                 else {                
  227.                     fprintf(outfile,"[5 2 1 2] 0 d\n");
  228.                 }
  229.                 break;
  230.                 
  231.         case 5 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  232.                 if (ai_color) {
  233.                     fprintf(outfile,"0 0 1 0 K\n");
  234.                 }
  235.                 else {                
  236.                     fprintf(outfile,"[4 3 1 3] 0 d\n");
  237.                 }
  238.                 break;
  239.                 
  240.         case 6 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  241.                 if (ai_color) {
  242.                     fprintf(outfile,"0 0 0 1 K\n");
  243.                 }
  244.                 else {                
  245.                     fprintf(outfile,"[2 2 2 4] 0 d\n");
  246.                 }
  247.                 break;
  248.                 
  249.         case 7 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  250.                 if (ai_color) {
  251.                     fprintf(outfile,"0 0.7 1 0 K\n");
  252.                 }
  253.                 else {                
  254.                     fprintf(outfile,"[2 2 2 2 2 4] 0 d\n");
  255.                 }
  256.                 break;
  257.                 
  258.         case 8 : fprintf(outfile,"%.2f w\n",AI_LW/AI_SC);
  259.                 if (ai_color) {
  260.                     fprintf(outfile,"0.5 0.5 0.5 0 K\n");
  261.                 }
  262.                 else {                
  263.                     fprintf(outfile,"[2 2 2 2 2 2 2 4] 0 d\n");
  264.                 }
  265.                 break;
  266.         }
  267.                 
  268.     ai_path_count = 0;
  269. }
  270.  
  271.  
  272. AI_move(x,y)
  273. unsigned int x,y;
  274. {
  275.     if (ai_stroke) fprintf(outfile,"S\n");
  276.     fprintf(outfile,"%.2f %.2f m\n", x/AI_SC, y/AI_SC);
  277.     ai_path_count += 1;
  278.     ai_stroke = TRUE;
  279. }
  280.  
  281.  
  282. AI_vector(x,y)
  283. unsigned int x,y;
  284. {
  285.     fprintf(outfile,"%.2f %.2f l\n", x/AI_SC, y/AI_SC);
  286.     ai_path_count += 1;
  287.     ai_stroke = TRUE;
  288.     if (ai_path_count >= 400) {
  289.         fprintf(outfile,"S\n%.2f %.2f m\n",x/AI_SC,y/AI_SC);
  290.         ai_path_count = 0;
  291.     }
  292. }
  293.  
  294.  
  295. AI_put_text(x,y,str)
  296. unsigned int x, y;
  297. char *str;
  298. {
  299. char ch;
  300.     if (ai_stroke) {
  301.         fprintf(outfile,"S\n");
  302.         ai_stroke = FALSE;
  303.     }
  304.     switch(ai_justify) {
  305.         case LEFT :   fprintf(outfile,"/_%s %d 0 0 0 z\n",ai_font,ai_fontsize);
  306.             break;
  307.         case CENTRE : fprintf(outfile,"/_%s %d 0 0 1 z\n",ai_font,ai_fontsize);
  308.             break;
  309.         case RIGHT :  fprintf(outfile,"/_%s %d 0 0 2 z\n",ai_font,ai_fontsize);
  310.             break;
  311.     }
  312.     if (ai_ang==0) {
  313.         fprintf(outfile,"[ 1 0 0 1 %.2f %.2f] e\n",
  314.             x/AI_SC,y/AI_SC - ai_fontsize/3.0);
  315.     }
  316.     else {
  317.         fprintf(outfile,"[ 0 1 -1 0 %.2f %.2f] e\n",
  318.             x/AI_SC - ai_fontsize/3.0,y/AI_SC);
  319.     }
  320.         
  321.     putc('(',outfile);
  322.     ch = *str++;
  323.     while(ch!='\0') {
  324.         if ( (ch=='(') || (ch==')') || (ch=='\\') )
  325.             putc('\\',outfile);
  326.         putc(ch,outfile);
  327.         ch = *str++;
  328.     }
  329.     fprintf(outfile,") t\nT\n");
  330.     ai_path_count = 0;
  331. }
  332.  
  333. int AI_text_angle(ang)
  334. int ang;
  335. {
  336.     ai_ang=ang;
  337.     return TRUE;
  338. }
  339.  
  340. int AI_justify_text(mode)
  341. enum JUSTIFY mode;
  342. {
  343.     ai_justify=mode;
  344.     return TRUE;
  345. }
  346.  
  347.